<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Image - 生成随机图片</title>
</head>

<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/Mock.js/1.0.1-beta3/mock-min.js"></script>
    <div class="box">
        展示内容:<div id="content"></div>
    </div>
    <script>
        let Random = Mock.Random;

        let list_arr = Mock.mock({

            //图片链接
            0: Random.image(),
            // => "http://dummyimage.com/125x125"
            1: Random.image('200x100'),
            // => "http://dummyimage.com/200x100"
            2: Random.image('200x100', '#fb0a2a'),
            // => "http://dummyimage.com/200x100/fb0a2a"
            3: Random.image('200x100', '#02adea', 'Hello'),
            // => "http://dummyimage.com/200x100/02adea&text=Hello"
            4: Random.image('200x100', '#00405d', '#FFF', 'Mock.js'),
            // => "http://dummyimage.com/200x100/00405d/FFF&text=Mock.js"
            5: Random.image('200x100', '#ffcc33', '#FFF', 'png', '!'),
            // => "http://dummyimage.com/200x100/ffcc33/FFF.png&text=!"

            //Base64
            6: Random.dataImage(),
            7: Random.dataImage('200x100'),
            8: Random.dataImage('200x100', 'Hello Mock.js!'),



        })

        //展示数据
        console.table(list_arr)
        x = document.getElementById("content");
        //将对象转为JSON
        //x.innerHTML = JSON.stringify(list_arr, null, '<br />');

        //将对象转为数组
        let arr = [];
        for (let item in list_arr) {
            arr.push(list_arr[item]);
        }

        //循环输出
        arr.forEach((item, index) => {
            x.innerHTML += "<li><img src=" + item + " /></li>";
        });


        console.log(Array.isArray(arr));//true 是数组

    </script>

</body>

</html>